﻿document.getElementById('nav').innerHTML = template('navs', navinfo7);
$('#nav li').eq(1).addClass('active');
var alldata = [];

$('#calendar').fullCalendar({
  header: {
    left: 'today prev,next',
    center: 'title',
    right: ''
  },
  handleWindowResize: false,
  eventLimit: true,
  monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  dayNames: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
  dayNamesShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
  today: ["今天"],
  firstDay: 1,
  titleFormat: 'YYYY年MM月',
  buttonText: {
    today: '本月',
    month: '月',
    week: '周',
    day: '日',
    prev: '上一月',
    next: '下一月'
  },
  /*loading: function (bool) {
   if (bool) {
   console.log('loading');
   } else {
   console.log('complete');
   }
   },*/
  dayClick: function (date, jsEvent, view) {//日期点击后弹出的jq ui的框，添加日程记录
    // console.log(new Date(date).pattern('yyyy-MM-dd'))
    // window.location.href = '/PM/Project/indexl41/' + new Date(date).pattern('yyyy-MM-dd');
  },
  eventClick: function (calEvent, jsEvent, view) {
    // console.log(calEvent.title);
    // console.log(calEvent.content);
    // console.log(calEvent.start._d);
    // var state = calEvent.content.split('#-#')[1];
    var index = parseInt(calEvent.content, 10);
    var data = alldata[index];
    var date = new Date(data.DayInfo).pattern('yyyy-MM-dd');
    var TeacherScheduleID = data.TeacherScheduleID;
    var ApplyID = data.ApplyID;
    var ProjectID = data.ProjectID;
    var url = '';
    // console.log(index, data)
    if (data.State === '无状态') {
      url = '/Teacher/Project/indexl41/' + date + '=' + TeacherScheduleID + '=' + ProjectID;
    } else {
      url = '/Teacher/Project/indexl42/' + date + '=' + ApplyID + '=' + ProjectID;
    }
    // console.log(url)
    window.open(url, '_self');

  },
  events: function (start, end, timezone, callback) {
    var d = new Date(end);
    var year = d.getFullYear();
    var month = d.getMonth();
    var day = '01';
    if (month === 0) {
      year = year - 1;
      month = 12;
    }
    var date = year + '-' + month + '-' + day + ' 00:00';
    // console.log(date);
    /*$.ajax({
     cache: false,
     async: false,
     url: '/api/CommonApi?API=GetTeacherSchedule',
     type: 'get',
     data: {
     Year: year,
     Month: month
     },
     dataType: 'json',
     success: function (data) {
     // console.log(data);
     if (data.Success) {
     var o = data.ApiParamObj;
     alldata = o;
     var i = 0;
     var l = o.length;
     $("#calendar").fullCalendar('removeEvents');
     for (; i < l; i++) {
     // console.log(o[i].IsSchedule)
     if (o[i].IsSchedule !== '未排程') {
     $("#calendar").fullCalendar('renderEvent', {
     // id: data[key].Name.ID,
     title: o[i].IsSchedule + '-' + o[i].State,
     start: moment(new Date(o[i].DayInfo).pattern('yyyy-MM-dd 00:00')).format(),
     end: moment(new Date(o[i].DayInfo).pattern('yyyy-MM-dd 00:00')).format(),
     // content: o[i].TeacherScheduleID + '#-#' + o[i].ApplyID + '#-#' + o[i].ProjectID
     content: i
     }, false);
     }

     }

     $('[data-toggle="tooltip"]').tooltip();
     }
     }
     });*/
  },
  eventAfterRender: function (event, element, view) {
    var index = parseInt(event.content, 10);
    var data = alldata[index];
    // element.attr('title', 'Tooltip on left');
    // element.attr('data-toggle', 'tooltip');
    // element.attr('data-placement', 'top');

    // element.html(event.title + '- 项目名称' );
    // element.parent().css({position: 'relative'}).append(html)
  },
  eventMouseover: function (event, jsEvent, view) {
    // $(this).next().removeClass('none');
  },
  eventMouseout: function (event, jsEvent, view) {
    // $(this).next().addClass('none');
  }
});

